package com.isdepci.project.gasEmission.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.gasEmission.domain.CustomerApportionment;
import com.isdepci.project.gasEmission.service.ICustomerApportionmentService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 客户分摊Controller
 *
 * @author isdepci
 * @date 2023-09-01
 */
@RestController
@RequestMapping("/apportionment/apportionment")
public class CustomerApportionmentController extends BaseController
{
    @Autowired
    private ICustomerApportionmentService customerApportionmentService;

    /**
     * 查询客户分摊列表
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerApportionment customerApportionment)
    {
        startPage();
        List<CustomerApportionment> list = customerApportionmentService.selectCustomerApportionmentList(customerApportionment);
        return getDataTable(list);
    }

    /**
     * 导出客户分摊列表
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:export')")
    @Log(title = "客户分摊", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerApportionment customerApportionment)
    {
        List<CustomerApportionment> list = customerApportionmentService.selectCustomerApportionmentList(customerApportionment);
        ExcelUtil<CustomerApportionment> util = new ExcelUtil<CustomerApportionment>(CustomerApportionment.class);
        return util.exportExcel(list, "apportionment");
    }

    /**
     * 获取客户分摊详细信息
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerApportionmentService.selectCustomerApportionmentById(id));
    }

    /**
     * 新增客户分摊
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:add')")
    @Log(title = "客户分摊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerApportionment customerApportionment)
    {
        return toAjax(customerApportionmentService.insertCustomerApportionment(customerApportionment));
    }

    /**
     * 修改客户分摊
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:edit')")
    @Log(title = "客户分摊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerApportionment customerApportionment)
    {
        return toAjax(customerApportionmentService.updateCustomerApportionment(customerApportionment));
    }

    /**
     * 删除客户分摊
     */
    @PreAuthorize("@ss.hasPermi('apportionment:apportionment:remove')")
    @Log(title = "客户分摊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerApportionmentService.deleteCustomerApportionmentByIds(ids));
    }
}
